window.onload= function () {
	
	// 捉元素

	click_item = document.getElementsByClassName('click_item');
	img_item = document.getElementsByClassName('img_item');

	click_right = document.getElementById("click_right");
	click_left = document.getElementById("click_left");

	banner = document.getElementById('banner');

	num = 0;
	//重复执行的方法
	function run() {
		//循环让所有隐藏
		for (var i = 0; i < img_item.length; i++) {
			img_item[i].style.display = "none";
			click_item[i].style.background="rgba(0,0,0,0.5)";
		}
		//让第num显示 
		img_item[num].style.display = "block";
		click_item[num].style.background="rgba(255,255,255,0.5)";
		// 走到最后一张，从头来
		if(num==img_item.length-1){
			num = 0;
		}else{
			num++;
		}
	}

	// 开启定时器
	time = setInterval(run,1000);

	// 进来关闭定时器
	banner.onmouseover = function () {
		clearInterval(time);
	}
	// 出来开户定时器
	banner.onmouseout = function () {
		time = setInterval(run,1000);
	}
	// 点击右
	click_right.onclick= function () {
		run();
	}
	// 点击右
	click_left.onclick= function () {
		if(num==1){
			num = click_item.length-1;
		}else if(num==0){
			num = click_item.length-2;
		}else{
			num-=2;
		}
		run();
	}
	// 循环给每个点加事件 //原生
	for (var i = 0; i < click_item.length; i++) {
		// 给每个点加一个属性，存储当前对象属于第几个
		click_item[i].index = i;
		click_item[i].onclick = function () {
			// 拿到当前对象的下标
			num = this.index;
			run();
		}
	}

	// console.log(click_item);
}
